package com.kai.mqtt.controller;

import com.kai.mqtt.statistics.IStatisticsService;
import com.kai.mqtt.data.Result;
import com.kai.mqtt.data.response.LatestDataResponse;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author weijk
 * @since 2024/6/19
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private IStatisticsService statisticsCacheService;

    /**
     * 获取最新数据
     *
     * @return 最新数据
     */
    @GetMapping("/latest/data")
    public Result<LatestDataResponse> getLatestData() {
        return Result.success(statisticsCacheService.getLatestData());
    }

    /**
     * 获取最新时间段内数据列表
     *
     * @return 最新数据列表
     */
    @GetMapping("/latest/data/list")
    public Result<List<LatestDataResponse>> listLatestData(@RequestParam("latest") Integer latest) {
        return Result.success(statisticsCacheService.listLatestData(latest));
    }
}
